#include "LocalScene.h"
#include "Utils/LogUtil.h"
#include "LocalEntity.h"
#include "Utils/StringUtil.h"
#include "Game/Component/Model.h"
#include "Render/RenderState.h"
#include "Render/Imgui/imgui.h"
#include "Math/Random.h"


void LocalScene::OnInit()
{
	mCamera.SetPosition(glm::vec3(0.f, 0.04f, 7.f));
	mCamera.LookAt(glm::vec3(0.f, 0.04f, 7.f), glm::vec3(0.f, 0.04f, 0.f));
	mCamera.UpdateViewMatrix();

	mCoordinateProcess = GetProcess<CoordinateProcess>("CoordinateProcess");
	mBvhProcess = GetProcess<BvhProcess>("BvhProcess");

	GeometryGenerator geometryGenerator;

	GeometryGenerator::MeshData panelData = geometryGenerator.CreatePanel(4.f, 4.f, glm::vec3(0.f, 1.f, 0.f));

	LocalEntity* panelEntity = CreateEntity<LocalEntity>("panel");
	panelEntity->AddComponent<Model>(panelData);
	panelEntity->GetTransform().SetLocalPosition(glm::vec3(0.f, -2.f, 0.f));
	panelEntity->GetTransform().UpdateMatrices();
	panelEntity->SetColor(glm::vec4(1.f));

	LocalEntity* oneEntity = CreateEntity<LocalEntity>();
	// oneEntity->AddComponent<Model>("FlyDragon.obj");
	oneEntity->AddComponent<Model>("Dragon.obj");
	oneEntity->GetTransform().SetLocalPosition(glm::vec3(0.f, -1.5f, 0.f));
	oneEntity->GetTransform().SetLocalScale(glm::vec3(0.5f));
	oneEntity->GetTransform().UpdateMatrices();
	oneEntity->SetColor(glm::vec4(1.f));
}

void LocalScene::OnExit()
{

}

void LocalScene::OnTick(float deltaTime)
{

}

void LocalScene::OnImgui()
{
	GameScene::OnImgui();


	ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);

	ImGui::Begin("Option");

	ImGui::InputInt("Bvh Depth", &mBvhProcess->mBvhDepth);

	ImGui::Checkbox("Use SAH", &mBvhProcess->mUseSAH);

	ImGui::Checkbox("Capture Ray", &mBvhProcess->mCaptureRay);

	ImGui::Checkbox("Only Show Hit", &mBvhProcess->mShowHit);

	ImGui::End();

}
